<?php
include_once './inc/isLogin.php';
include_once("./../fckeditor/fckeditor.php") ;

//bof fckeditor
if(true){
	$oFCKeditor = new FCKeditor('content') ;//字段名字
	$oFCKeditor->BasePath = './../fckeditor/' ;
	$oFCKeditor->Height = 400; 
	$oFCKeditor->Width = 720; 
	$oFCKeditor->Config['EnterMode'] = 'br';
	
	//注意修改上传目录：fckeditor\editor\filemanager\connectors\php\config.php
	//$Config['UserFilesPath'] = '/tf/php_fck/userfiles/' ;
	
	//上传的图片命名规则:
	//fckeditor\editor\filemanager\connectors\php\commands.php
	//$sFileName=time().rand(0,100).".".$sExtension;
	
}
//end fckeditor
?>
<?php

	//准备装载数据
	require_once("./../includes/configure.php");
	require_once("./../includes/database.php");
	$db = Database::Connect();
	$var = $_GET['article_common'];
	//更新
	if($_POST['submit']){
		if($_POST['act']=='add_service'||$_POST['act']=='add_zpbz'){
			if($_POST['act']=='add_service'){
				$desc = 'jyfw';
			}elseif($_POST['act']=='add_zpbz'){
				$desc = 'zpbz';
			}
			$C = $_POST['C'];
			$A = $_POST['A'];
			$content = $_POST['content'];
			$sql = "insert into common_article (this_id,description,`content`,A,C,add_time)
						values(null,'$desc','$content','$A','$C',now())";
			$db->Execute($sql);
			$update_result = '添加完成';
		}else if($_POST['act']=='update'){
			$this_id = $_POST['this_id'];
			$C = $_POST['C'];
			$A = $_POST['A'];
			$content = $_POST['content'];
			$sql = "update common_article set `C`='$C',`A`=$A,`content`='$content' WHERE this_id=$this_id";
			$db->Execute($sql);
			$update_result = '更新完成';
		}elseif($_POST['act']=='del'){
			$this_id = $_POST['this_id'];
			$sql = "delete from common_article WHERE this_id=$this_id";   
			$db->Execute($sql);
			$update_result = '成功删除';
		}elseif($_POST['act']=='before_update'){
			$this_id = $_POST['this_id'];
			$sql = "select * from common_article WHERE this_id=$this_id";
			$row = $db->GetSingleRow($sql);
			$oFCKeditor->Value = $row->content;//<?php echo $row->guanggao_content;? >
			$title = '更新信息';
		}
		
	}
	//end 更新
	if($var=='add_service'){
		$title = '添加交易服务信息';
	}elseif($var=='add_zpbz'){
		$title = '添加正品保证信息';
	}
	if($var=='list_service'){//add_service
		$title = '交易服务信息列表';
		$sql = "SELECT * FROM common_article WHERE description='jyfw' order by A,add_time desc";   
		$article_result = $db->GetResultSet($sql);
	}else if($var=='list_zpbz'){//add_zpbz
		$title = '正品保证信息列表';
		$sql = "SELECT * FROM common_article WHERE description='zpbz' order by A,add_time desc";   
		$article_result = $db->GetResultSet($sql);
	}
?>
<div class="top-bar" style=" border-bottom: 2px solid #FF7700;padding:10px;">
	<?//<a href="#" class="button">ADD NEW </a>?>
	<h1><?php echo $title;?></h1>
</div><br />

<br/><br/><br/><br/>
<span class="green info">
<?php 
if($update_result){
	echo $update_result;
	echo '<br/><br/>';
}
?>
</span>

<?php
if($var=='add_service' || $var=='add_zpbz'){
?>
	<div style="padding: 10px;">
		<form action="" method="post">
			<div style="padding:5px;">
				排序: <input type="text" name="A" value="0" style="width:30px;">&nbsp;<input type="submit" name="submit" value=" 添加 "><br/><br/>标题: 
				<input type="text" name="C" value="" style="width:500px;">
				<input type="hidden" name="act" value="<?php echo $var;?>">
			</div>
			<br/>
			<?php $oFCKeditor->Create() ; //就像一个普通input一样,放在form中?>
		</form>
	</div>
<?php
}else if($_POST['act']=='before_update'){
//更新
?>
	<div style="padding: 10px;">
		<form action="" method="post">
			<div style="padding:5px;">
				排序: <input type="text" name="A" value="<?php echo $row->A;?>" style="width:30px;">&nbsp;
				<input type="submit" name="submit" value=" 更新 "><br/><br/>
				标题: <input type="text" name="C" value="<?php echo $row->C;?>" style="width:500px;">
				<input type="hidden" name="this_id" value="<?php echo $row->this_id;?>">
				<input type="hidden" name="act" value="update">
			</div>
			<br/>
			<?php $oFCKeditor->Create() ; //就像一个普通input一样,放在form中?>
		</form>
	</div>
<?php
}else{
?>
	<div>
	<?php
		$index_this = 1;
		while($row = mysql_fetch_array($article_result)){
		?>
			<div style="border-bottom:dashed 1px gray;height:25px;margin:5px;">
				<a href="../common_article.php?id=<?php echo $row['this_id'];?>" target="blank">
				<?php echo $index_this++;?>.&nbsp;
				<span><?php echo $row['C'];?></span>
				</a>
				<form action="" method="post" style="float:right;">
					<input type="hidden" name="this_id" value="<?php echo $row['this_id'];?>">
					<input type="hidden" name="act" value="del">
					<input type="submit" name="submit" value="删除" style="border: medium none;color: blue;">
				</form>
				<form action="" method="post" style="float:right;">
					<input type="hidden" name="this_id" value="<?php echo $row['this_id'];?>">
					<input type="hidden" name="act" value="before_update">
					<input type="submit" name="submit" value="修改" style="border: medium none;color: blue;">
				</form>
				<div style="clear:both;"></div>
			</div>
		<?php
			//echo $row['value'];
		}
	?>
	</div>
<?php
}

$db->close();
?>